<template>
    <div>
        <h1> {{  this.$store.state.userInfo.username  }}</h1>
        <h1> {{  this.$store.state.userInfo.role  }}</h1>  
       <div>

          <tr>
             <td>
            关键字姓名
       <el-input v-model="vo.keyWord" placeholder="请输入内容" style="width:223px"></el-input>
       年龄段<el-input-number v-model="vo.begin" @change="handleChange" :min="23" :max="60" label="描述文字"></el-input-number>
       ~
       <el-input-number v-model="vo.end" @change="handleChange" :min="23" :max="60" label="描述文字"></el-input-number>

        <el-button  type="info" v-on:click="search" >查询</el-button>

     
        <el-button type="danger" v-on:click="deletebyids">批量删除</el-button>
         

          </td>
          <td  v-if="showsrole">
            <el-button type="primary" v-on:click="add">添加</el-button>
          </td>
          
          </tr>

          

          
        
        </div>



        




        <el-table
            :data="tableData"
            border
            style="width: 100%">
            <el-table-column
            fixed
            prop="id"
            label="医生主键"
            width="150">
            </el-table-column>
            <el-table-column
            prop="name"
            label="姓名"
            width="120">
            </el-table-column>
            <el-table-column
            prop="gender"
            label="性别"
            width="120">
            </el-table-column>
            <el-table-column
            prop="pro_id"
            label="省"
            width="120">
            </el-table-column>
            <el-table-column
            prop="city_id"
            label="城市"
            width="300">
            </el-table-column>
            <el-table-column
            prop="birthday"
            label="出生年月"
            width="120">
            </el-table-column>
            <el-table-column
            prop="skillname"
            label="技能"
            width="100">
            </el-table-column>
            <el-table-column
            prop="deptname"
            label="科室"
            width="100">

            <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text" size="small">编辑</el-button>
                <el-button @click="handleDelete(scope.row)" type="text" size="small">删除</el-button>
             
            </template>
            </el-table-column>
        </el-table>


        <el-pagination
            layout="prev, pager, next"
            :current-page="currentPage"
            :page-size="pageSize"
            :total="totalSize"
            @current-change="handleChange"
            >
        </el-pagination>


        <el-dialog title="医生信息修改" :visible.sync="dialogFormVisible">

        <el-form :model="form" :rules="rules" ref="form" class="demo-ruleForm">
    
            <el-form-item label="主键" :label-width="formLabelWidth">
            <el-input v-model="form.id" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="姓名" :label-width="formLabelWidth" prop="name">
            <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="性别" :label-width="formLabelWidth" prop="gender">

            <el-radio v-model="form.gender" label="1">男</el-radio>
            <el-radio v-model="form.gender" label="2">女</el-radio>

            </el-form-item>

            <el-form-item label="出生日期" :label-width="formLabelWidth" prop="birthday">
            <el-date-picker
            v-model="form.birthday"
            type="date"
            placeholder="选择日期">
            </el-date-picker>
            </el-form-item>

        <el-form-item label="地区" :label-width="formLabelWidth">
         
        <el-cascader
            v-model="form.cityIds"
            :options="options"
            @change="handleChange"></el-cascader>
         </el-form-item>


        <el-form-item label="科室" :label-width="formLabelWidth" prop="departId" >
        <template>
        <el-radio-group v-model="form.deptname">
            <el-radio :label="1">外科</el-radio>
            <el-radio :label="2">内科</el-radio>
            <el-radio :label="3">心脑</el-radio>
            <el-radio :label="4">五官</el-radio>
            <el-radio :label="5">牙科</el-radio>
            <el-radio :label="6">产科</el-radio>
        </el-radio-group>
        </template>
        </el-form-item>

        <el-form-item label="技能" :label-width="formLabelWidth" prop="skillname">
        
        <template>
        <el-checkbox-group v-model="form.skillname">
            <el-checkbox label="1">麻醉</el-checkbox>
            <el-checkbox label="2">接生</el-checkbox>
            <el-checkbox label="3">整容</el-checkbox>
            <el-checkbox label="4">牛皮藓</el-checkbox>
            <el-checkbox label="5">儿科感冒</el-checkbox>
       
        </el-checkbox-group>
        </template>
        </el-form-item>



    <el-form-item label="姓名" :label-width="formLabelWidth" prop="name">
            
      <el-upload
        action="this.$baseUrl +'/upload/img'"
        list-type="picture-card"
        :on-preview="handlePictureCardPreview"
        :on-remove="handleRemove"
        :on-success="uploadImg">
        <i class="el-icon-plus"></i>
      </el-upload>
      <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="form.head_img" alt="">
      </el-dialog>
    </el-form-item>






      


     <el-form-item label="个人头像" :label-width="formLabelWidth">
      <el-input v-model="form.head_img" autocomplete="off"></el-input>
     <el-upload
        class="upload-demo"
        ref="upload"
        action="https://127.0.0.1:8089/upload/img"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :file-list="fileList"
        :auto-upload="false">
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
        </el-upload>
        </el-form-item>
        </el-form>

        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="saveOrupdate(form)">确 定</el-button>
        </div>
        </el-dialog>




    </div>
</template>

<script>
export default {

    //方法块
    methods: {


       uploadImg(url) {
               alert("zhigao") ;
       let cc =   JSON.parse(url) ;
         alert(cc) ;
      //上传成功后，赋值
      this.imageUrl = url;
      this.form.headImg = url;
    },
       handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePictureCardPreview(file) {
        alert("test preview" ) ;
        // this.dialogVisible = true ;
        // alert("chuziygao test") ;
        // this.form.head_img = file.url;
        // this.dialogVisible = true;
        // alert(this.form.head_img);
      }
      ,
        submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },


      submitUpload(url) {
        alert(url.name ) ;
        this.form.head_img = this.fileList ;
        alert(this.form.head_img) ;
       // this.$refs.upload.submit();
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },


        //2级地区的变化函数
        handleChange(){

        },

         saveOrupdate(formName) {
           
           let id = formName.id ;
          let cc =  formName.skillname ;
            alert("111") ;
            alert(cc) ;
            
              alert("222") ;
              
      //          axios.post("http://127.0.0.1:8089/tb-doc/add",this.formName)
      // .then(res=>{
      //   //先关闭开户的小窗口，再刷新一次
      //   this.dialogFormVisible = false ;
      //   alert("333") ;
      //   this.search();
      // })

      }


        ,
        handleDelete(row){
         alert( "shcnu" + row);

        },
        handleClick(row){
            alert("bianji" + row);
            this.dialogFormVisible= true ;

        },
        handleChange(){
          alert("page") ;
     
        },
        add(){
          this.dialogFormVisible = true ;
            alert("add") ;
        },
        deletebyids(){
            alert("delete") ;
        },

      handleChange(value) {
        console.log(value);
      },

        search(){
        
           let bshow = this.$store.state.userInfo.role  ;
           this.showsrole = bshow ;
           
          
           console.log(this.showsrole) ;
            
        }
        
    },
    // 创建页面时候的第一个动作 ，包括查询数据的产生以及所有初始化值得自动识别
    created() {
  
        this.search();
        
    },

   //页面控件的数据的初始化值 
    data() {
    return {
       // 图片是否显示
      dialogVisible: false,
      showsrole: true,
      vo:{"keyWord":"","begin":0,"end":100},
      tableData: [{
          date: '2016-05-02',
          name: '王小虎',
          province: '上海',
          city: '普陀区',
          address: '上海市普陀区金沙江路 1518 弄',
          zip: 200333
        }
        ],
        currentPage:1,
        pageSize:5,
        totalSize:100,
        dialogFormVisible: false,
        form: {
            id:'',

          name: '',
          gender:'',
          pro_id: '',
          cityIds: '',
          birthday: '',
          skillname: [],
           head_img: '',
          deptname: ''
        },
        // 校验规则
         rules: {
          name: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 3, max: 30, message: '长度在 3 到 30 个字符', trigger: 'blur' }
          ],
          deptname: [
            { required: true, message: '请选择科室', trigger: 'blur' }
          ],
          gender: [
            { required: true, message: '请选择性别', trigger: 'blur' }
          ],
          birthday: [
            { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
          ],
            skillname: [
            { required: true, message: '请填写活动形式', trigger: 'blur' }
          ]
          

        }
        ,
         options: [{
          value: '1',
          label: '资源',
          children: [{
            value: '2',
            label: 'Axure Components'
          }, {
            value: '3',
            label: 'Sketch Templates'
          }, {
            value: '4',
            label: '组件交互文档'
          }]
        }]
         ,
        fileList: []
  


    }
  }
    
}
</script>